import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/components/Layout/index.vue'
import TemplateRouteView from '@/components/TemplateRouteView/index.vue'

const search = (resolve) => require(['@/views/search/index.vue'], resolve)


const home = (resolve) => require(['@/views/home/index.vue'], resolve)

const user = (resolve) => require(['@/views/personCenter/index.vue'], resolve)
const baseInfo = (resolve) => require(['@/views/personCenter/baseInfo/index.vue'], resolve)
const fastMatch = (resolve) => require(['@/views/personCenter/matchPolicy/fastMatch.vue'], resolve)
const accurateMatch = (resolve) => require(['@/views/personCenter/matchPolicy/accurateMatch.vue'], resolve)


const publishAchievement = (resolve) => require(['@/views/personCenter/innovativeResources/publishAchievement.vue'], resolve)

const enterpriseExam = (resolve) => require(['@/views/personCenter/enterpriseExam.vue'], resolve)


const policy = (resolve) => require(['@/views/policy/index.vue'], resolve)
const policyDetail = (resolve) => require(['@/views/policy/detail.vue'], resolve)
// const techSource = (resolve) => require(['@/views/techSource/index.vue'], resolve)
const techNeed = (resolve) => require(['@/views/techNeed/index.vue'], resolve)
const techNeedDetail = (resolve) => require(['@/views/techNeed/detail.vue'], resolve)


const expertBase = (resolve) => require(['@/views/expertBase/index.vue'], resolve)
const expertBaseDetail = (resolve) => require(['@/views/expertBase/detail.vue'], resolve)



const schools = (resolve) => require(['@/views/schools/index.vue'], resolve)
const schoolDetail = (resolve) => require(['@/views/schools/detail.vue'], resolve)

// const investOrganization = (resolve) => require(['@/views/investOrganization/index.vue'], resolve)

const techAchievements = (resolve) => require(['@/views/techAchievements/index.vue'], resolve)
const techAchievementDetail = (resolve) => require(['@/views/techAchievements/detail.vue'], resolve)


const techExpert = (resolve) => require(['@/views/techExpert/index.vue'], resolve)
const techExpertList = (resolve) => require(['@/views/techExpert/list.vue'], resolve)
const techExpertDetail = (resolve) => require(['@/views/techExpert/detail.vue'], resolve)


const governmentService = (resolve) => require(['@/views/governmentService/index.vue'], resolve)
const servicelist = (resolve) => require(['@/views/serviceDynamic/index.vue'], resolve)
const serviceDetail = (resolve) => require(['@/views/serviceDynamic/detail.vue'], resolve)
const enterpriseService = (resolve) => require(['@/views/enterpriseService/index.vue'], resolve)


const techTool = (resolve) => require(['@/views/techTool/index.vue'], resolve)
const techShowList = (resolve) => require(['@/views/techShowList/index.vue'], resolve)
const techShowDetail = (resolve) => require(['@/views/techShowList/detail.vue'], resolve)


const innovateActivity = (resolve) => require(['@/views/innovateActivity/index.vue'], resolve)
const innovateActivDetail = (resolve) => require(['@/views/innovateActivity/detail.vue'], resolve)
const windowCity = (resolve) => require(['@/views/windowCity/index.vue'], resolve)

const locationCity = (resolve) => require(['@/views/windowCity/locationIndex.vue'], resolve)
const locationPolicyDetail = (resolve) => require(['@/views/windowCity/locationPolicyDetail.vue'], resolve)
const locationCompanyDetail = (resolve) => require(['@/views/windowCity/companyDetail.vue'], resolve)



const innovatePlatform = (resolve) => require(['@/views/innovatePlatform/index.vue'], resolve)


// 科技资源
const techSourceChildren = [{
	path: 'expertBase',
	component: expertBase,
	name: 'expertBase',
	meta: {
		title: '专家智库'
	}
},
{
	path: 'expertBase/expertBaseDetail/:id',
	component: expertBaseDetail,
	name: 'expertBaseDetail',
	meta: {
		title: '专家详情'
	},
	hidden: true
},
{
	path: 'techAchievements',
	component: techAchievements,
	name: 'techAchievements',
	meta: {
		title: '科技成果库'
	},
},
{
	path: 'techAchievements/techAchievementDetail/:id',
	component: techAchievementDetail,
	name: 'techAchievementDetail',
	meta: {
		title: '科技成果详情'
	},
	hidden: true

},

{
	path: 'techNeed',
	component: techNeed,
	name: 'techNeed',
	meta: {
		title: '技术需求库'
	}
},
{
	path: 'techNeed/techNeedDetail/:id',
	component: techNeedDetail,
	name: 'techNeedDetail',
	meta: {
		title: '技术需求详情'
	},
	hidden: true
},

{
	path: 'schools',
	component: schools,
	name: 'schools',
	meta: {
		title: '高校院所'
	}
},
{
	path: 'schools/schoolDetail/:id',
	component: schoolDetail,
	name: 'schoolDetail',
	meta: {
		title: '高校详情'
	},
	hidden: true

},
// {
// 	path: 'investOrganization',
// 	component: investOrganization,
// 	name: 'investOrganization',
// 	meta: {
// 		title: '投资机构'
// 	}
// },
{
	path: 'innovatePlatform',
	component: innovatePlatform,
	name: 'innovatePlatform',
	meta: {
		title: '创新平台'
	}
}
]

// 创新服务
const innovateServiceChild = [{
	path: 'techExpert',
	component: techExpert,
	name: 'techExpert',
	meta: {
		title: '专家入驻'
	},
},

{
	path: 'governmentService',
	component: governmentService,
	name: 'governmentService',
	meta: {
		title: '政府服务'
	},
	breadHidden: true
},

{
	path: 'enterpriseService',
	component: enterpriseService,
	name: 'enterpriseService',
	meta: {
		title: '企业服务'
	}
},

]

// 技转工具
const techToolChild = [
	{
		path: 'techShowList',
		component: techShowList,
		name: 'techShowList',
		meta: {
			title: '在线展厅'
		}
	},
	{
		path: 'techShowList/techShowDetail/:type/:id',
		component: techShowDetail,
		name: 'techShowDetail',
		meta: {
			title: '在线展厅详情'
		},
		hidden: true
	},

]

export const userRouteList =
{
	path: '/user',
	component: TemplateRouteView,
	redirect: '/user/userInfo',
	name: 'user',
	meta: {
		title: '个人中心',
		icon: 'el-icon-menu',
	},
	breadHidden: true,
	hidden: 0,

	children: [
		{
			path: 'userInfo',
			name: 'userInfo',
			redirect: '/user/userInfo/baseInfo',
			component: user,
			meta: {
				title: '账户信息',
				icon: 'el-icon-menu',
			},
			hidden: 0,
			children: [
				{
					path: 'baseInfo',
					name: 'userBaseInfo',
					meta: {
						title: '基本信息',
						icon: 'el-icon-menu',
					},

					hidden: 0,
					component: baseInfo,
				},
			],
		},
		{
			path: 'matchPolicy',
			name: 'matchPolicy',
			redirect: '/user/matchPolicy/fastmatch',
			component: user,
			meta: {
				title: '政策匹配',
				icon: 'el-icon-menu',
			},
			hidden: 0,
			children: [
				{
					path: 'fastmatch',
					name: 'fastmatch',
					meta: {
						title: '快速评估',
						icon: 'el-icon-menu',
					},

					hidden: 0,
					component: fastMatch,
				},
				{
					path: 'accuratematch',
					name: 'accuratematch',
					meta: {
						title: '精准评估',
						icon: 'el-icon-menu',
					},

					hidden: 0,
					component: accurateMatch,
				},


			],
		},

		{
			path: 'innovativeResources',
			name: 'innovativeResources',
			redirect: '/user/innovativeResources/publishAchievement',
			component: user,
			meta: {
				title: '创新资源',
				icon: 'el-icon-menu',
			},
			hidden: 0,
			children: [
				{
					path: 'publishAchievement',
					name: 'publishAchievement',
					meta: {
						title: '发布成果',
						icon: 'el-icon-menu',
					},

					hidden: 0,
					component: publishAchievement,
				}
			],
		},

		{
			path: 'enterpriseExam',
			name: 'innovativeResources',
			redirect: '/user/enterpriseExam/examIndex',
			meta: {
				title: '企业体检',
				icon: 'el-icon-menu',
			},
			component: user,
			children: [
				{
					path: 'examIndex',
					name: 'examIndex',
					meta: {
						title: '企业体检',
						icon: 'el-icon-menu',
					},

					hidden: 0,
					component: enterpriseExam,
				}
			]
		}
	]
}


// 导航栏 
export const navList = [
	{
		path: '/home',
		component: home,
		name: 'home',
		meta: {
			title: '首页'
		}
	},



	// {
	// 	path: '/user/:menu',
	// 	component: user,
	// 	name: 'user',
	// 	meta: {
	// 		title: '个人中心'
	// 	},
	// 	hidden: true
	// },
	{
		path: '/search',
		component: search,
		name: 'search',
		hidden: true,
		meta: {
			title: '全局搜索'
		}
	},
	{
		path: '/policy',
		component: policy,
		name: 'policy',
		meta: {
			title: '政策匹配'
		}
	},
	{
		path: '/policy/policyDetail/:id',
		component: policyDetail,
		name: 'policyDetail',
		meta: {
			title: '政策详情'
		},
		hidden: true

	},

	{
		path: '/techSource',
		component: TemplateRouteView,
		redirect: '/techSource/techNeed',
		name: 'techSource',
		meta: {
			title: '科技资源'
		},
		breadHidden: true,
		children: [
			...techSourceChildren,
		]
	},
	{
		path: '/innovateService',
		component: TemplateRouteView,
		name: 'innovateService',
		redirect: '/innovateService/techExpert',
		meta: {
			title: '创新服务'
		},
		breadHidden: true,
		children: [
			...innovateServiceChild,
			// {
			//   path: 'techExpert/detail',
			//   component: techExpertDetail,
			//   name: '技术专家详情',
			//   meta: { title: '技术专家详情' }
			// }
		]
	},
	{
		path: '/techTool',
		component: TemplateRouteView,
		name: 'techTool',
		redirect: '/techTool/techShowList',
		meta: {
			title: '技转工具'
		},
		breadHidden: true,
		children: [
			...techToolChild,
			// {
			//   path: 'techExpert/detail',
			//   component: techExpertDetail,
			//   name: '技术专家详情',
			//   meta: { title: '技术专家详情' }
			// }
		]
	},
	// {
	// 	path: '/techTool',
	// 	component: techTool,
	// 	name: 'techTool',
	// 	meta: {
	// 		title: '技转工具'
	// 	}
	// },

	{
		path: '/serviceDynamic/servicelist/:typeId',
		component: servicelist,
		name: 'servicelist',
		meta: {
			title: '服务动态'
		},
		hidden: true
	},
	{
		path: '/serviceDynamic/servicelist/:typeId/serviceDetail/:id',
		component: serviceDetail,
		name: 'serviceDetail',
		meta: {
			title: '服务动态详情'
		},
		hidden: true
	},
	{
		path: '/techExpertList',
		component: techExpertList,
		name: 'techExpertList',
		meta: {
			title: '技术专家列表'
		},
		hidden: true,
	},
	{
		path: 'techExpertList/techExpertDetail/:id',
		component: techExpertDetail,
		name: 'techExpertDetail',
		meta: {
			title: '技术专家详情'
		},
		hidden: true
	},

	{
		path: '/innovateActivity',
		component: innovateActivity,
		name: 'innovateActivity',
		meta: {
			title: '创新活动'
		}
	},
	{
		path: 'innovateActivity/innovateActivDetail/:id',
		component: innovateActivDetail,
		name: 'innovateActivDetail',
		meta: {
			title: '创新活动详情'
		},
		hidden: true
	},
	{
		path: '/windowCity',
		component: windowCity,
		name: 'windowCity',
		meta: {
			title: '城市之窗'
		}
	},
	{
		path: '/locationCity/:id',
		component: locationCity,
		name: 'locationCity',
		meta: {
			title: '地区之窗'
		},
		hidden: true
	},

	{
		path: '/locationCity/:id/locationPolicyDetail/:detailId',
		component: locationPolicyDetail,
		name: 'locationPolicyDetail',
		meta: {
			title: '政策详情'
		},
		hidden: true
	},
	{
		path: '/locationCity/:id/locationCompanyDetail/:detailId',
		component: locationCompanyDetail,
		name: 'locationCompanyDetail',
		meta: {
			title: '明星企业详情'
		},
		hidden: true
	},

]



// 公共路由
export const constantRoutes = [{
	path: '/login',
	name: 'login',
	component: (resolve) => require(['@/views/register/index'], resolve),
	hidden: true
},
{
	path: '/register',
	name: 'register',
	component: (resolve) => require(['@/views/register/index'], resolve),
	hidden: true
},
{
	path: '/forgetPassword',
	name: 'forgetPassword',
	component: (resolve) => require(['@/views/register/index'], resolve),
	hidden: true
},
// {
// 	path: '/user',
// 	component: (resolve) => require(['@/views/perseoncenter/index'], resolve),
// 	hidden: true
// },


{
	path: '/404',
	component: (resolve) => require(['@/views/error/404'], resolve),
	hidden: true
},
{
	path: '/401',
	component: (resolve) => require(['@/views/error/401'], resolve),
	hidden: true
},

{
	path: '',
	component: Layout,
	redirect: 'home',
	children: [
		...navList,
		userRouteList,
	]
},
{
	path: "*",
	redirect: "/404"
}

	// {
	//   path: '/user',
	//   component: Layout,
	//   hidden: true,
	//   redirect: 'noredirect',
	//   children: [
	//     {
	//       path: 'profile',
	//       component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
	//       name: 'Profile',
	//       meta: { title: '个人中心', icon: 'user' }
	//     }
	//   ]
	// }
]

// 整理所有路由 为一个数组



const readyList = (list) => {
	let routes = JSON.parse(JSON.stringify(list))
	let finObj = {}
	for (let i = 0; i < routes.length; i++) {
		const element = routes[i];
		let children = element.children
		if (children) {
			let childrenObj = readyList(children)
			Object.assign(finObj, childrenObj)
		}
		// if (!element.hidden) {
		//   finObj[element.name] = element
		// }
		finObj[element.name] = element
	}
	return finObj
}
export const reallyRouteList = readyList(navList)


export default new Router({
	mode: 'history', // 去掉url中的#
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})
